﻿package com.dbm.model;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;

import com.dbm.dao.CtlPublicDao;
import com.dbm.dao.OwnerCodeDao;
import com.dbm.dao.PublicDao;
import com.dbm.util.AsnInfo;
import com.dbm.util.OrderProcess;
import com.dbm.util.SoInfo;

public class WmsToOrderProcess {
	DateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
	CtlPublicDao ctlPublicDao = new CtlPublicDao();
	public PublicDao publicDao = new PublicDao();
	private OwnerCodeDao ownerCodeDao = new OwnerCodeDao();//DBM---ownercodedao
	/**
	 * 将AsnInfo 转换为 OrderProcess--流水
	 * @param asnInfo
	 * @return
	 */
	public synchronized OrderProcess byAsnInfo(AsnInfo asnInfo) throws Exception{
		OrderProcess orderProcess = new OrderProcess();
		orderProcess.setID("LS"+ctlPublicDao.getEntryOrderIdBySeq("SEQTORDERPROCESS"));
		orderProcess.setORDERCODE(asnInfo.getENTRYORDERCODE());
		orderProcess.setORDERID(asnInfo.getASNNO());
		orderProcess.setORDERTYPE(asnInfo.getORDERTYPE());
		orderProcess.setWAREHOUSECODE(asnInfo.getWAREHOUSECODE());
		orderProcess.setPROCESSSTATUS(asnInfo.getSTATUS());
		//将货主写入流水信息的remark字段
		orderProcess.setREMARK(asnInfo.getOWNERCODE());
		orderProcess.setOPERATETIME(format.format(new Date()));
		orderProcess.setSENDFLAG("NO");
		orderProcess.setCUSTOMERID(publicDao.getCtlCustomerIdByWmsCustomerid(ownerCodeDao.getOwnerCodeByCustomerId(asnInfo.getOWNERCODE())));
		return orderProcess;
	}
	/**
	 * 将 soInfo 转换为 OrderProcess--流水
	 * @param soInfo
	 * @return
	 */
	public synchronized OrderProcess bySoInfo(SoInfo soInfo) throws Exception{
		OrderProcess orderProcess = new OrderProcess();
		orderProcess.setID("LS"+ctlPublicDao.getEntryOrderIdBySeq("SEQTORDERPROCESS"));
		orderProcess.setORDERCODE(soInfo.getDELIVERYORDERCODE());
		orderProcess.setORDERID(soInfo.getORDERNO());
		orderProcess.setORDERTYPE(soInfo.getORDERTYPE());
		orderProcess.setWAREHOUSECODE(soInfo.getWAREHOUSECODE());
		orderProcess.setPROCESSSTATUS(soInfo.getSTATUS());
		//将货主写入 流水信息的remark字段
		orderProcess.setREMARK(soInfo.getOWNERCODE());
		orderProcess.setOPERATETIME(format.format(new Date()));
		orderProcess.setSENDFLAG("NO");
		orderProcess.setCUSTOMERID(publicDao.getCtlCustomerIdByWmsCustomerid(soInfo.getOWNERCODE()));
		return orderProcess;
	}
}	
